package com.sharing.library.service;

import com.sharing.library.entity.File;
import com.sharing.library.repository.FileRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhanghaixuan
 * @create 2018/3/19-上午10:05
 **/
@Service
public class FileService {

    @Autowired
    private FileRepository fileRepository;

    /**
     * 保存
     */
    public Long upload(byte[] fileStream,String fileName,Long fileSize,String fileType){
        File file = new File();

        file.setIostream(fileStream);
        file.setFileName(fileName);
        file.setFileType(fileType);
        file.setFileSize(fileSize);

        File save = fileRepository.save(file);

        return  save.getId();
    }

    /**
     * 读取
     */
    public File download(Long fileId){
        File one = fileRepository.findOne(fileId);

        return one;
    }

}
